Number1One
New Member
- Joined
- Mar 1, 2019
- Messages
- 16
- Office Version
- 365
- Platform
- Windows
Hi All,
New to VBA/Macros trying to learn whilst piecing together examples i've seen, think what i've got works but is long winded and needs a different macro for each split and will require tweaking if/as the report changes.
Im trying to break out a report in 1 worksheet into 5 different worksheets all with different criteria with no blank rows.
1 Report info:
Has 1 match column in A and row 1 to pull data in from another workbook.
Rows 4 to 24 are Header/Totals/ product info etc
Row 25 on wards is data
All split worksheets wants columns:
E, F, G,K*,N Then a variety of O,P,Q,R,S,T,U depending on which worksheet it is.
*K is a value given in the VBA depending on Worksheet
WS 1 only wants rows where Column:
G="NH" and J="BF"
WS 2 only wants rows where Column:
G="H" and J="BF"
WS 3 only wants rows where Column:
H<>"WB" and J="BF"
WS 4 only wants rows where Column:
H="WB" and J="BF"
WS only wants rows where Column:
J="LY"
Thanks for any help.
Here is the example i currently have for WS1:
New to VBA/Macros trying to learn whilst piecing together examples i've seen, think what i've got works but is long winded and needs a different macro for each split and will require tweaking if/as the report changes.
Im trying to break out a report in 1 worksheet into 5 different worksheets all with different criteria with no blank rows.
1 Report info:
Has 1 match column in A and row 1 to pull data in from another workbook.
Rows 4 to 24 are Header/Totals/ product info etc
Row 25 on wards is data
All split worksheets wants columns:
E, F, G,K*,N Then a variety of O,P,Q,R,S,T,U depending on which worksheet it is.
*K is a value given in the VBA depending on Worksheet
WS 1 only wants rows where Column:
G="NH" and J="BF"
WS 2 only wants rows where Column:
G="H" and J="BF"
WS 3 only wants rows where Column:
H<>"WB" and J="BF"
WS 4 only wants rows where Column:
H="WB" and J="BF"
WS only wants rows where Column:
J="LY"
Thanks for any help.
Here is the example i currently have for WS1:
Sub NH() Dim ds As Worksheet
Dim dr As Worksheet
Set ds = ThisWorkbook.Sheets("All")
Set dr = ThisWorkbook.Sheets("NH")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'last row db sheet, last row report sheet
dLR = ds.Cells(Rows.Count, 1).End(xlUp).Row
drLR = dr.Cells(Rows.Count, 1).End(xlUp).Row + 1
'clear last report
dr.Range("A1:M" & drLR).ClearContents
y = 4
'loop through db
For x = 4 To dLR
If IsEmpty(ds.Cells(x, 2)) Or ds.Cells(x, 2) = "Count" Then
'add to report sheet
dr.Cells(y, 1) = ds.Cells(x, 5)
dr.Cells(y, 2) = ds.Cells(x, 6)
dr.Cells(y, 3) = ds.Cells(x, 7)
dr.Cells(y, 4) = ds.Cells(x, 11)
dr.Cells(y, 5) = ds.Cells(x, 14)
dr.Cells(y, 6) = ds.Cells(x, 15)
y = y + 1
End If
Next x
'starting row report sheet
y = 25
'loop through db
For x = 25 To dLR
If ds.Cells(x, 7) = "NH" And ds.Cells(x, 10) = "BF" Then
'add to report sheet
dr.Cells(y, 1) = ds.Cells(x, 5)
dr.Cells(y, 2) = ds.Cells(x, 6)
dr.Cells(y, 3) = "L3"
dr.Cells(y, 4) = ds.Cells(x, 11)
dr.Cells(y, 5) = ds.Cells(x, 14)
dr.Cells(y, 6) = ds.Cells(x, 15)
y = y + 1
End If
Next x
Application.ScreenUpdating = True
Application.Calculation = xlCalculationManual
End Sub