Inputbox variable to then insert formula and loop through worksheets

Eurekaonide

Active Member
Joined
Feb 1, 2010
Messages
422
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.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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?
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

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