Excel VBA

fouling91

New Member
Joined
Oct 25, 2023
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hi every one;
I'm looking for a VBA code capable of copying data from columns "C2:D227612" and pasting them into empty rows in "A3:B227612". For example: range C2:D2 must be pasted into A3:B3 (empty row) and repeat this for all 227612 data. I need to put the Longitude-Latitude contained in columns C and D just below each Longitude-latitude combination in columns A. Can You Help Me please
Capture-data-copy.JPG
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Assuming the exact same layout:
VBA Code:
Sub FillTheGaps()
    With ActiveSheet
        With Intersect(.UsedRange, .Range("A:B")).SpecialCells(xlCellTypeBlanks)
            .Formula = "=c2"
            .Value = .Value
        End With
    End With
End Sub
 
Upvote 0
Assuming the exact same layout:
VBA Code:
Sub FillTheGaps()
    With ActiveSheet
        With Intersect(.UsedRange, .Range("A:B")).SpecialCells(xlCellTypeBlanks)
            .Formula = "=c2"
            .Value = .Value
        End With
    End With
End Sub
Hi , thanks, but the code dosn't work. The code only copies the columns I want. Why did you put "=c2"?. I'd like to copy the lines contained in the "C2: D227612" range and paste them into the empty boxes in (A2: B227612), respecting the order. For example: Row "C2:D2" should be copied and pasted into "A3:B3", and so on for the rest up to "Cn:Dn" in "An+1:Bn+1". After executing your code it looked like this :
 

Attachments

  • Code-VBA-Run.JPG
    Code-VBA-Run.JPG
    63.6 KB · Views: 7
Upvote 0
As I said, my code assumes the EXACT same layout, so it assumes the first empty cell in column A is cell A3. IN cell A3, my code puts the formula =C2. ANd the line is constructed in such a way that this formula is then "copied" to all empty rows in columns A and B, thus filling them with the content two columns to the right and one row up.

To cater for different positions of the gaps, please adapt the code to:

VBA Code:
Sub FillTheGaps()
    With ActiveSheet
        With Intersect(.UsedRange, .Range("A:B")).SpecialCells(xlCellTypeBlanks)
            .FormulaR1C1 = "=R[-1]C[2]"
            .Value = .Value
        End With
    End With
End Sub
 
Upvote 0
Thanks for your code, but it didn't work😅. Can you adjust it😁?
 

Attachments

  • run 2.JPG
    run 2.JPG
    81 KB · Views: 7
Upvote 0
As I said, my code assumes the EXACT same layout, so it assumes the first empty cell in column A is cell A3. IN cell A3, my code puts the formula =C2. ANd the line is constructed in such a way that this formula is then "copied" to all empty rows in columns A and B, thus filling them with the content two columns to the right and one row up.

To cater for different positions of the gaps, please adapt the code to:

VBA Code:
Sub FillTheGaps()
    With ActiveSheet
        With Intersect(.UsedRange, .Range("A:B")).SpecialCells(xlCellTypeBlanks)
            .FormulaR1C1 = "=R[-1]C[2]"
            .Value = .Value
        End With
    End With
End Sub
Upon testing your code, the issue seems to be with this line:

VBA Code:
            .Value = .Value
 
Upvote 0
Upon testing your code, the issue seems to be with this line:

VBA Code:
            .Value = .Value
Slight adjustment to the code:

VBA Code:
Sub FillTheGaps()
    With ActiveSheet
        With Intersect(.UsedRange, .Range("A:B"))
            .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C[2]"
            .Value = .Value
        End With
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top