VBA Problem with inputbox finding and copying data

Palucci

Banned user
Joined
Sep 15, 2021
Messages
138
Office Version
  1. 365
Platform
  1. Windows
The macro stopped working for me, I don't know why, it should copy data from data_wb.Sheets to wbMe. data_wb should run in the shade. There is no error, however, the data is not looking, as if it would not know in which tab. should in "Adekwatnosc" someone knows why? when I go after f8, it jumps straight away "Set loc = .Cells.Find (what: = vDate)
If Not loc Is Nothing Then do to end if "
VBA Code:
Dim vDate As Date
Dim wbMe As Workbook
Dim ws As Worksheet
Dim inputbx As String
Dim loc As Range, lc As Long
Dim MyFolder As String, ThisMonth As String
Dim MyFile As String

'Zmieniamy nagłówek na short date w pliku z makrem'

Set wbMe = ActiveWorkbook
With wbMe.Sheets("input_forecast").Rows("1:1")
    .Copy
    .PasteSpecial Paste:=xlPasteValues
    .NumberFormat = "YYYY-MM-DD"
  End With
  
'Otwieramy plik automatycznie ze wskazanego folderu'
  

MyFolder = "C:\Users\V1410190\Documents\FOLDERY ROBOCZE"


MyFile = Dir(MyFolder & "\Kopia PKO BH Plan kroczac1*.xlsm")


If MyFile <> "" Then

Set data_wb = Workbooks.Open(MyFolder & "\" & MyFile, UpdateLinks:=0)

Else
Exit Sub
End If

'Usuwamy alerty o akutliazacji itp'
Application.ThisWorkbook.UpdateLinks = xlUpdateLinksNever '2
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.AskToUpdateLinks = False

'Zmieniamy nagłówek na short date w pliku z planem kroczącym'

With data_wb.Sheets("Adekwatnosc").Rows("1:1")
   .Value = .Value
   .NumberFormat = "YYYY-MM-DD"
End With
'input box - wpisujemy date zgodnie z podanym formatem'
 Do
        inputbx = InputBox("Enter Date, FORMAT; YYYY-MM-DD", Format(VBA.Now, "YYYY-MM-DD"))
        If inputbx = vbNullString Then Exit Sub
        On Error Resume Next
        vDate = DateValue(inputbx)
        On Error GoTo 0
        DateIsValid = IsDate(vDate)
        If Not DateIsValid Then MsgBox "Please enter a valid date.", vbExclamation
    Loop Until DateIsValid
       
' Wyszukujemy find daty w nagłówku -> kopiujemy -> wklejamy je do pliku z makrem we wskazane w makrze miejscu'
     

     With data_wb.Worksheets("Adekwatnosc")
        Set loc = .Cells.Find(what:=vDate)
      If Not loc Is Nothing Then
            lc = .Cells(loc.Row, Columns.Count).End(xlToLeft).Column
            .Range(.Cells(109, loc.Column), .Cells(123, lc)).Copy
      Set locPaste = wbMe.Sheets("input_forecast").Cells.Find(what:=vDate)
      wbMe.Sheets("input_forecast").Cells(27, locPaste.Column).PasteSpecial Paste:=xlPasteValues
      Application.CutCopyMode = False
      
      lc1 = .Cells(loc.Row, Columns.Count).End(xlToLeft).Column
            .Range(.Cells(138, loc.Column), .Cells(138, lc1)).Copy
      Set locPaste = wbMe.Sheets("input_forecast").Cells.Find(what:=vDate)
      wbMe.Sheets("input_forecast").Cells(21, locPaste.Column).PasteSpecial Paste:=xlPasteValues
      Application.CutCopyMode = False
      
      
        End If
    End With
'Zamykamy plik bez zapisywania'
data_wb.Close SaveChanges:=False
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,214,523
Messages
6,120,042
Members
448,940
Latest member
mdusw

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