VBA to Paste values if condition met

dogpile

New Member
Joined
Oct 24, 2005
Messages
21
Hi All!
I'm looking for VBA code to copy and paste values in the range D37:F54 in the below example, but for only the rows that are not sub-totals (i.e. paste values for accounts that do not start with a "PL")
Right now all rows have formulas in them that populate the data from somewhere else in the sheet.
Thanks in advance!


Excel 2013 64 bit
CDEF
32201820182018
33ActualForecastForecast
34JanuaryFebruaryMarch
35ACCOUNT
36
37420010 - Base Rent Revenue346,620346,451347,202
38PL410_RES - Gross rent346,620346,451347,202
39426050 - Base Rent Vacancy - Offset- (24,102)(20,487)
40PL420_RES - Building Vacancy- (24,102)(20,487)
41426020 - New Lease Promo- (1,215)(1,215)
42PL425_RES - Promotions- (1,215)(1,215)
43424010 - Parking Rental Revenue21,29220,66720,667
44PL430_RES - Parking revenue21,29220,66720,667
45424040 - Other Rental Income- - -
46424040_RENTAL - Other Rental Income for rental- 1,3501,350
47428070 - Utilities Recovery(8,253)6,5006,500
48480130 - Service Revenue(147)8383
49480150 - Miscellaneous Revenue- - -
50480150_RENTAL - Miscellaneous Revenue - Revenue for rental120100100
51480190 - Telecommunication Commission Revenue(6,825)1,4911,491
52PL499_RES - Other income(15,105)9,5249,524
53PL490_RES - All other income(15,105)9,5249,524
54PL400_RES - Total Revenue352,807351,326355,691
Sheet1
 

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
Try:
Code:
Sub PasteValues()
    Application.ScreenUpdating = False
    Range("C36:F54").Select
    Selection.AutoFilter
    Range("C36:F54").AutoFilter Field:=1, Criteria1:="<>*PL*"
    Range("D37:F54").SpecialCells(xlCellTypeVisible).Value = Range("D37:F54").SpecialCells(xlCellTypeVisible).Value
    If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for your reply - this almost got me there - only issue, it looks like it's pasting the values of the first row to all rows (other than the rows with "PL" which is good).
Here is the result:


Excel 2013 64 bit
CDEF
32201820182018
33ActualForecastForecast
34JanuaryFebruaryMarch
35ACCOUNT
36
37420010 - Base Rent Revenue346,620346,451347,202
38PL410_RES - Gross rent346,620346,451347,202
39426050 - Base Rent Vacancy - Offset346,620346,620346,620
40PL420_RES - Building Vacancy- (24,102)(20,487)
41426020 - New Lease Promo346,620346,451347,202
42PL425_RES - Promotions- (1,215)(1,215)
43424010 - Parking Rental Revenue346,620346,620346,620
44PL430_RES - Parking revenue21,29220,66720,667
45424040 - Other Rental Income346,620346,451347,202
46424040_RENTAL - Other Rental Income for rental346,620346,451347,202
47428070 - Utilities Recovery346,620346,451347,202
48480130 - Service Revenue346,620346,451347,202
49480150 - Miscellaneous Revenue346,620346,451347,202
50480150_RENTAL - Miscellaneous Revenue - Revenue for rental346,620346,451347,202
51480190 - Telecommunication Commission Revenue346,620346,451347,202
52PL499_RES - Other income(15,105)9,5249,524
53PL490_RES - All other income(15,105)9,5249,524
54PL400_RES - Total Revenue352,807351,326355,691
Sheet1
 
Upvote 0
Try:
Code:
Sub PasteValues()
    Application.ScreenUpdating = False
    Dim rng As Range
    Range("C36:F54").AutoFilter Field:=1, Criteria1:="<>*PL*"
    For Each rng In Range("D37:D54").SpecialCells(xlCellTypeVisible)
        Range("D" & rng.Row & ":F" & rng.Row).Copy
        Range("D" & rng.Row).PasteSpecial xlPasteValues
    Next rng
    If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for this - it seems to work now, but as soon as I amend the code to accommodate a larger table (i.e. c36:AA500") the run time is extremely slow.
Back to the drawing board...
 
Upvote 0
How about
Code:
Sub PasteValues()

    Dim Rng As Range
    
    Range("C36:F36").AutoFilter 1, "<>*PL*"
    For Each Rng In Range("D37", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible).Areas
      Rng.Resize(, 24).Value = Rng.Resize(, 24).Value
    Next Rng
    ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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