Copy column value but skip over to next column if empty

inwonderland7

New Member
Joined
Oct 11, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have 2 worksheets: Master Sheet and Sheet2

I would like the data in columns O-X from Master Sheet to copy over to Sheet2 cells C20-25 & E20-25.

Basically, if the column has value then enter into C20 but if not, skip the column and enter in the next column value to C20.
If C20 is filled then fill in cell C21 with the next column data.

And so on.

Here are some screenshots to help visualize.

Any help is greatly appreciated!


EDIT:
Here is my current code for the other form cells if it helps.

Module1
VBA Code:
Sub PopulateSheets()
Dim i As Integer
Dim ws As Worksheet
Dim row_num As Integer
Dim lastSheet As Integer

row_num = 3 ' starting row number on Master Sheet sheet
lastSheet = Worksheets("ACF Set Up").Range("B5").Value + 2 ' get last sheet number from ACF Set Up sheet

For i = 3 To lastSheet
Set ws = Worksheets(i)
If Worksheets("Master Sheet").Cells(row_num, 1).Value = "" Then ' skip the row if column A is blank
row_num = row_num + 1
i = i - 1 ' decrement the counter so we repeat the same sheet
Else ' populate the sheet if column A is not blank
ws.Range("C6").Value = Worksheets("Master Sheet").Cells(row_num, 1).Value
ws.Range("F5").Value = Worksheets("Master Sheet").Cells(row_num, 3).Value
ws.Range("F6").Value = Worksheets("Master Sheet").Cells(row_num, 14).Value
ws.Range("C12").Value = Worksheets("Master Sheet").Cells(row_num, 11).Value
If Worksheets("Master Sheet").Cells(row_num, 7).Value = "" Then
ws.Range("D10").Value = Worksheets("Master Sheet").Cells(row_num, 9).Value
Else
ws.Range("D10").Value = "N/A"
End If
If Worksheets("Master Sheet").Cells(row_num, 7).Value = "" Then
ws.Range("F10").Value = Worksheets("Master Sheet").Cells(row_num, 10).Value
Else
ws.Range("F10").Value = "N/A"
End If
If Worksheets("Master Sheet").Cells(row_num, 7).Value = "" Then
ws.Range("D9").Value = "N/A"
Else
ws.Range("D9").Value = Worksheets("Master Sheet").Cells(row_num, 7).Value
End If
If Worksheets("Master Sheet").Cells(row_num, 7).Value = "" Then
ws.Range("F9").Value = "N/A"
Else
ws.Range("F9").Value = Worksheets("Master Sheet").Cells(row_num, 8).Value
End If
If Worksheets("Master Sheet").Cells(row_num, 5).Value = "" Then
ws.Range("D14").Value = ""
Else
ws.Range("D14").Value = Worksheets("Master Sheet").Cells(row_num, 5).Value
End If
If Worksheets("Master Sheet").Cells(row_num, 6).Value = "" Then
ws.Range("F14").Value = ""
Else
ws.Range("F14").Value = Worksheets("Master Sheet").Cells(row_num, 6).Value
End If
If Worksheets("Master Sheet").Cells(row_num, 4).Value = "" Then
ws.Range("D15").Value = ""
Else
ws.Range("D15").Value = Worksheets("Master Sheet").Cells(row_num, 3).Value
End If
If Worksheets("Master Sheet").Cells(row_num, 4).Value = "" Then
ws.Range("F15").Value = ""
Else
ws.Range("F15").Value = Worksheets("Master Sheet").Cells(row_num, 4).Value
End If
If Worksheets("Master Sheet").Cells(row_num, 12).Value = "" Then
ws.Range("D16").Value = ""
Else
ws.Range("D16").Value = Worksheets("Master Sheet").Cells(row_num, 12).Value
End If
If Worksheets("Master Sheet").Cells(row_num, 8).Value = "" Then
ws.Range("A9").Value = ""
Else
ws.Range("A9").Value = "X"
End If
If Worksheets("Master Sheet").Cells(row_num, 10).Value = "" Then
ws.Range("A10").Value = ""
Else
ws.Range("A10").Value = "X"
End If
If Worksheets("Master Sheet").Cells(row_num, 11).Value = "" Then
ws.Range("A12").Value = ""
Else
ws.Range("A12").Value = "X"
End If
If Worksheets("Master Sheet").Cells(row_num, 6).Value = "" Then
ws.Range("A14").Value = ""
Else
ws.Range("A14").Value = "X"
End If
If Worksheets("Master Sheet").Cells(row_num, 4).Value = "" Then
ws.Range("A15").Value = ""
Else
ws.Range("A15").Value = "X"
End If
row_num = row_num + 1 ' increment row number for the next sheet
End If
Next i
End Sub

Module2
VBA Code:
Sub DuplicateSheets()
Dim i As Integer
Dim newSheet As Worksheet
Dim numSheets As Integer

numSheets = Worksheets("ACF Set Up").Range("B19").Value

For i = 3 To numSheets + 2 ' start at sheet 3 and create numSheets sheets
Sheets("Sheet2").Copy after:=Sheets(Sheets.Count)
Set newSheet = ActiveSheet
newSheet.Name = "Sheet" & i
Next i
End Sub
 

Attachments

  • 2023-10-11_11-06-29.png
    2023-10-11_11-06-29.png
    24.2 KB · Views: 8
  • 2023-10-11_11-06-05.png
    2023-10-11_11-06-05.png
    17 KB · Views: 10
Last edited by a moderator:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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