Looping Through Two Columns

homerl2409

New Member
Joined
Dec 26, 2019
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have two columns: A & B. Column A has a list of Items and Column B has a list of dates.

A.PNG


What I am trying to do in Excel VBA is copy everything that's in column A into another sheet and then copy each cell on column B alongside each value in column A until everything in column B has been copied. Like this:


b.PNG

I don't know where to start. Please help :(

I also posted here: Looping Through Two Columns, Looping Through Two Columns in Excel VBA, and on Reddit
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
VBA Code:
Sub homerl()
   Dim Rng As Range, Cl As Range
   Dim Nxtrw As Long
   Nxtrw = 1
   With Sheets("Sheet1")
      Set Rng = .Range("A1", .Range("A" & Rows.Count).End(xlUp))
      Rng.Copy Sheets("Sheet2").Range("A1").Resize(Rng.Count * .Range("B" & Rows.Count).End(xlUp).Row)
      For Each Cl In .Range("B1", .Range("B" & Rows.Count).End(xlUp))
         Sheets("sheet2").Range("B" & Nxtrw).Resize(Rng.Count).Value = Cl.Value2
         Nxtrw = Nxtrw + Rng.Count
      Next Cl
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

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