VBA code that uses if/then and multiple sheets

BAQI

New Member
Joined
Dec 2, 2022
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
This code involves three sheets: "MAIN SHEET" "Custom Labels" & "Normal Labels"

This is what I would like for it to do:

On "Custom Labels" and "Normal Labels"
Unprotects both sheets - PW: "123"

On "Custom Labels" sheet:
Clears A2:A200, B2:B200, C2:C200, D2:D200, E2:E200, F2:F200
On "Normal Labels" sheet:
Clears A2:A200, B2:B200, C2:C200, D2:D200, E2:E200, F2:F200, G2:G200

On "MAIN SHEET":

Column A2:A100 - Has to have the text "C", or "N" otherwise moves to the next row.

For all the rows that have "C" in column A it performs this for only applicable rows:

Sub Serials()
Dim lr, i, j, k, m As Long
lr = Sheets("MAIN SHEET").Cells(Rows.Count, "B").End(xlUp).Row
j = 2
For i = 2 To lr
k = Sheets("MAIN SHEET").Cells(i, 19)
For m = k To k + Sheets("MAIN SHEET").Cells(i, 20) - Sheets("MAIN SHEET").Cells(i, 19)
Sheets("C").Cells(j, 1) = Sheets("MAIN SHEET").Cells(i, 2)
Sheets("C").Cells(j, 6) = Sheets("MAIN SHEET").Cells(i, 2)
Sheets("C").Cells(j, 2) = Sheets("MAIN SHEET").Cells(i, 10)
Sheets("C").Cells(j, 11) = m
j = j + 1
Next m
k = k + 1
Next i
End Sub

For all the rows that have "N" in column A it performs this for that row:

It looks for the quantity in column "U" on "main sheet", then copies over the following information onto sheet "Normal Labels" for the same row:

Column C ---> Column A2:A200
Column B ---> Column B2:B200
Column H ---> Column C2:C200
Column U ---> Column D2:D200
Column V ---> Column E2:E200
Column H ---> Column F2:F200

It will add this information only for the first instance for that row:

Column W ---> Column G2:G200
Column X ---> Column H2:H200

Then it protects both of those sheets again with a password.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Good morning. I'm hoping someone might be able to help. I appreciate it.
 
Upvote 0
I've been playing around with it, and I'm still a bit lost.
 
Upvote 0

Forum statistics

Threads
1,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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