Inputbox variable to then insert formula and loop through worksheets

Eurekaonide

Active Member
Joined
Feb 1, 2010
Messages
387
Hi

I'm trying to use an Input box to obtain a variable which then relates to a column in each worksheet in order to then filter on all the Actuals and paste a formula all the way down. This needs to lop through each worksheet. I have the below but it errors on with block or object.

VBA Code:
Sub Actuals_Formula()
'
' Actuals_Formula Macro
   
Dim Rnd As Range
Dim k As Variant
  
   k = InputBox("Enter Week Number to find")
   If k = "" Then Exit Sub
  
   Range("A2").Activate
  
  ActiveSheet.Range("2:2").AutoFilter Field:=2, Criteria1:="Actual"
  
   With ActiveSheet
      Set Rnd = .Rows(2).Find(What:=k, After:=ActiveCell, LookIn:=xlValues, LookAt _
         :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
         False, SearchFormat:=False)
        
        
      If Rnd Is Nothing Then
        MsgBox "Week not found"
        Exit Sub
      End If
      
      With Intersect(.UsedRange, Rnd.Columns, Rows(3))
         With Selection.FormulaR1C1 = "=SUMIFS(Actuals!C9,Actuals!C4,R1C1,Actuals!C8,RC1)"
            Selection.NumberFormat = "_-* #,##0.00_-;-* #,##0.00_-;_-* ""-""_-;_-@_-"
            Selection.Copy
            Range(Selection, Selection.End(xlDown).Offset(-1, 0)).Select
            ActiveSheet.Paste
            ActiveSheet.Range("2:2").AutoFilter Field:=2
         End With
         Application.CutCopyMode = False
      End With
   
   End With
   
End Sub

Thank you for your help, its driving me crazy !

ActiveSheet.Range("2:2").AutoFilter Field:=2, Criteria1:="Actual"

and insert the this formula and copy it down on all the filtered cells. This also needs to loop through each worksheet.

ActiveCell.FormulaR1C1 = "=SUMIFS(Actuals!C9,Actuals!C4,R1C1,Actuals!C8,RC1)"
Selection.NumberFormat = "_-* #,##0.00_-;-* #,##0.00_-;_-* ""-""_-;_-@_-"
Selection.Copy
Range(Selection, Selection.End(xlDown).Offset(-1, 0)).Select
ActiveSheet.Paste

I keep getting the object or with block error again.
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,682
Office Version
  1. 365
Platform
  1. Windows
What is the point of asking for help, if you then ignore what has been offered & change most of the code back to what you had to begin with?
 

Eurekaonide

Active Member
Joined
Feb 1, 2010
Messages
387
Apologies, I thought I had used the formats discussed. I am stuck in understanding how to select from a filter and then place formula in only those filtered cells once the correct column had been located via the input box.
I have not used input box before. I have now reverted to a case select code and trying to get it to work that way.
I appreciate your help so far, thank you.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,682
Office Version
  1. 365
Platform
  1. Windows
I supplied you the code to do the first part of your requirement, which looped through the sheets & you have now dumped most of that & gone back to active sheet.
Can you please post the code I gave you previously?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,848
Messages
5,627,244
Members
416,233
Latest member
Riddlemethis

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
Top