Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 632247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:03:20+00:00 2026-05-13T20:03:20+00:00

I have an excel sheet with values in columns A, B and C like

  • 0

I have an excel sheet with values in columns A, B and C like this:

      A      B      C
1    8.22   1.99902 32.48974
2    8.22   3.04698 33.92426
3    8.22   2.26374 33.1547
4    8.22   2.78227 33.2593
6    8.22   2.46798 33.34269
6    8.22   2.57802 33.67131
7    8.22   2.46798 32.7427
8    8.22   2.57802 33.07131

There is also a cell (say for example F1) containing a value that can only be 1,2 or 3.

I would like to create a commandbutton to perform the following job:
For each pair of lines (which cosnist a group) insert 2 new lines below them, and populate them with values like this (suppose we are dealing with the group residing in lines 9 and 10)

If F1 = 1 THEN
A11 = A10   B11 = B10   C11 = C9
A12 = A10   B12 = B9    C12 = C10

If F1 = 2 THEN
A11 = A10   B11 = B10   C11 = C9
A12 = A9   B12 = B10    C12 = C10

If F1 = 3 THEN
A11 = A10   B11 = B9   C11 = C10
A12 = A9   B12 = B10    C12 = C10

Finaly set the background color for the newely inserted lines to yellow.

Could you please help me accomplish this task?

P.S. Once a button like this was pressed, what would you recommend for an Undo capability?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:03:21+00:00Added an answer on May 13, 2026 at 8:03 pm

    Supposing that your data start at Row 1 and the commandbutton’s name is CommandButton1, try adding the following code in CommandButton1 click event. I used a bottom-up approach because it was easier for me to handle row numbers while looping.

    Private Sub CommandButton1_Click()
        Dim lines_count As Integer
        Dim fixed_column As Integer
        Dim i As Integer
        lines_count = Application.WorksheetFunction.Count(Range("A:A"))
        fixed_column = Range("F1").Value
    
        For i = lines_count + 2 To 4 Step -2 
            Rows(i - 1 & ":" & i).Select
            Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    
            Select Case fixed_column
            Case 1
                Cells(i - 1, 1).Value = Cells(i - 2, 1).Value
                Cells(i, 1).Value = Cells(i - 2, 1).Value
                Cells(i - 1, 2).Value = Cells(i - 2, 2).Value
                Cells(i, 2).Value = Cells(i - 3, 2).Value
                Cells(i - 1, 3).Value = Cells(i - 3, 3).Value
                Cells(i, 3).Value = Cells(i - 2, 3).Value
            Case 2
                Cells(i - 1, 1).Value = Cells(i - 2, 1).Value
                Cells(i, 1).Value = Cells(i - 3, 1).Value
                Cells(i - 1, 2).Value = Cells(i - 2, 2).Value
                Cells(i, 2).Value = Cells(i - 2, 2).Value
                Cells(i - 1, 3).Value = Cells(i - 3, 3).Value
                Cells(i, 3).Value = Cells(i - 2, 3).Value
            Case 3
                Cells(i - 1, 1).Value = Cells(i - 2, 1).Value
                Cells(i, 1).Value = Cells(i - 3, 1).Value
                Cells(i - 1, 2).Value = Cells(i - 3, 2).Value
                Cells(i, 2).Value = Cells(i - 2, 2).Value
                Cells(i - 1, 3).Value = Cells(i - 2, 3).Value
                Cells(i, 3).Value = Cells(i - 2, 3).Value
            End Select
            Range("A" & CStr(i - 1) & ":C" & CStr(i)).Select
            Selection.Interior.ColorIndex = 6
    
        Next
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an excel spreadsheet that has 2 columns. Something like this |ColA |
I have an Excel sheet that looks like this: |A B C D -----------------------------------------------------------------------------------
In a cell in Excel sheet I have a Date value like: 01/01/2010 14:30:00
I have an excel sheet laid out like so: +--id---+--val--+--timestamp--+ | 01 | 1.2
I have a Excel sheet with two columns and I need to create new
I have two columns in excel like the following a,apple a,bannana a,orange a,plum b,apple
Hai i have an excel sheet, in that i need to calculate some values
I have an excel sheet with 8 rows and 4096 columns.I am trying to
So I've got this Excel sheet of employees which have all the information about
I currently have an excel sheet with one of the columns being in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.