VBA Help needed

jpj31

New Member
Joined
Apr 26, 2022
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Sub Building_Concrete()
Dim ws As Worksheet, ws1 As Worksheet
Dim lastrow As Long
Dim totalrow As Long
Dim lc As Range

Set ws = Worksheets("OSTcopy")
Set ws1 = Worksheets("BUILDING CONC")


Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


' Initialize to start at bottom of column O
totalrow = ws1.Cells(Rows.Count, "IL").End(xlUp).Row
' last row in column F
lastrow = ws.Cells(Rows.Count, 6).End(xlUp).Row

' Copy the formatted OST Report and insert into Template
ws.Rows("11:" & lastrow).Copy
ws1.Activate
ws1.Rows("19:19").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False

' Make sure the OST formulas are pasted values
ws.Rows("11:" & lastrow).Copy
ws1.Activate
ws1.Rows("19:19").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ws1.Activate


' Loop through rows
Do
' Exit if at row 10
If totalrow = 19 Then Exit Do
' Copy formula from example row
If Range("F", totalrow).Value <> "" Then
ws1.Range("N16:IL16").Copy
ws1.Range("N19:IL" & totalrow).PasteSpecial xlPasteAll
End If

Loop

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub

Everything above the bolded red colored section is working. What I'm trying to do is copy formulas from row 16 to every row that has any data in column "F", from the "Total" row. The total row varies based on the size of the report that's being inserted from another tab. I made sure to copy over the entire sub, in case I've got something wrongly defined for the totalrow. Any help would be greatly appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Maybe?
VBA Code:
If Range("F" & totalrow).Value <> "" Then
 
Upvote 0
Solution
That fixes one issue but raises another. Now it just blows up and is never able to finish calculating. I've trimmed out the section that's causing it to bomb out. There's something I'm doing wrong, but I'm not good enough to figure out why. Below is where I'm at:

Sub Macro2()
'
' Macro2 Macro
Dim totalrow As Long

Set ws = Worksheets("OSTcopy")
Set ws1 = Worksheets("BUILDING CONC")


Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual


' Initialize to start at bottom of column IL
totalrow = ws1.Cells(Rows.Count, "IL").End(xlUp).Row

' Loop through rows
Do
' Exit if at row 19
If totalrow = 19 Then Exit Do
' Copy formula from example row
If Range("J" & totalrow).Value <> "" Then
ws1.Range("A16:D16").Copy
ws1.Range("A" & totalrow).PasteSpecial xlPasteAll
End If

Loop

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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