data without formulas returned

KlausW

Active Member
Joined
Sep 9, 2020
Messages
453
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone
I use this VBA code to import data from multiple files, it works really well.
But in column K in the source file there are some formulas with values, now I would like the data without formulas returned.
Anyone who can help?
Any help will be appreciated.
Best Regards
Klaus W

VBA Code:
Sub Master_Rektangelafrundedehjørner2_Klik()



Dim stgF As String, stgP As String

Dim wb As Workbook

Dim ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Master") 'Assuming that "Master" is the destination sheet name.



stgP = "D:\DNBR 2024\Hoffet\Hoffet overigt over middage og receptioner\" '---->Insert your file path.

stgF = Dir(stgP & "\*.xls*")





Application.ScreenUpdating = False

Application.Calculation = xlCalculationManual

Application.DisplayAlerts = False



Do While stgF <> vbNullString



Set wb = Workbooks.Open(stgP & "\" & stgF)



With wb.Sheets(1)

.UsedRange.Offset(2).Copy ws.Range("A" & Rows.Count).End(3)(2)

ws.Columns.AutoFit

End With



wb.Close Save = False

stgF = Dir()

Loop



Application.Calculation = xlCalculationAutomatic

Application.DisplayAlerts = True

Application.ScreenUpdating = True

Application.DisplayCommentIndicator = xlNoIndicator



Worksheets("Master").Cells.EntireRow.AutoFit



End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Do you need only the values and not the formatting for the whole sheet? If so, I think this will work. so long as the ranges in the changed line are the same size:
VBA Code:
Sub Master_Rektangelafrundedehjørner2_Klik()

Dim stgF As String, stgP As String
Dim wb As Workbook, ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Master") 'Assuming that "Master" is the destination sheet name.

stgP = "D:\DNBR 2024\Hoffet\Hoffet overigt over middage og receptioner\" '---->Insert your file path.
stgF = Dir(stgP & "\*.xls*")

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

Do While stgF <> vbNullString
    Set wb = Workbooks.Open(stgP & "\" & stgF)
  
    With wb.Sheets(1)
        '.UsedRange.Offset(2).Copy ws.Range("A" & Rows.Count).End(3)(2)
        ' Copy the values only, but ranges must be the same size:
        ws.Range("A" & Rows.Count).End(3)(2).Value2 = .UsedRange.Offset(2).Value2
        ws.Columns.AutoFit
    End With
  
    wb.Close Save = False
    stgF = Dir()
Loop

Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.DisplayCommentIndicator = xlNoIndicator

Worksheets("Master").Cells.EntireRow.AutoFit

End Sub
 
Upvote 0
Do you need only the values and not the formatting for the whole sheet? If so, I think this will work. so long as the ranges in the changed line are the same size:
VBA Code:
Sub Master_Rektangelafrundedehjørner2_Klik()

Dim stgF As String, stgP As String
Dim wb As Workbook, ws As Worksheet

Set ws = ThisWorkbook.Worksheets("Master") 'Assuming that "Master" is the destination sheet name.

stgP = "D:\DNBR 2024\Hoffet\Hoffet overigt over middage og receptioner\" '---->Insert your file path.
stgF = Dir(stgP & "\*.xls*")

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

Do While stgF <> vbNullString
    Set wb = Workbooks.Open(stgP & "\" & stgF)
 
    With wb.Sheets(1)
        '.UsedRange.Offset(2).Copy ws.Range("A" & Rows.Count).End(3)(2)
        ' Copy the values only, but ranges must be the same size:
        ws.Range("A" & Rows.Count).End(3)(2).Value2 = .UsedRange.Offset(2).Value2
        ws.Columns.AutoFit
    End With
 
    wb.Close Save = False
    stgF = Dir()
Loop

Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.DisplayCommentIndicator = xlNoIndicator

Worksheets("Master").Cells.EntireRow.AutoFit

End Sub
Hi Vogateer it doesn't work it only takes cells A3 and A4. Sincerely, Klaus W
 
Upvote 0
Try changing the With wb.Sheets(1) section with this:

Rich (BB code):
    With wb.Sheets(1)
        '.UsedRange.Offset(2).Copy ws.Range("A" & Rows.Count).End(3)(2)
        ' Copy the values only, but ranges must be the same size:
        With .UsedRange.Offset(2)
            ws.Range("A" & Rows.Count).End(3)(2).Resize(.Rows.Count, .Columns.Count).Value2 = .Value2
        End With
        ws.Columns.AutoFit
    End With
 
Upvote 0
Try changing the With wb.Sheets(1) section with this:

Rich (BB code):
    With wb.Sheets(1)
        '.UsedRange.Offset(2).Copy ws.Range("A" & Rows.Count).End(3)(2)
        ' Copy the values only, but ranges must be the same size:
        With .UsedRange.Offset(2)
            ws.Range("A" & Rows.Count).End(3)(2).Resize(.Rows.Count, .Columns.Count).Value2 = .Value2
        End With
        ws.Columns.AutoFit
    End With
Hi
Alex Blakenburg it copies as it should but it does not include the comments that are in columns C:J, can you help? Regards Klaus W
 
Upvote 0
OK can you replace the whole section I gave you last time from With to End With, and use this instead.

VBA Code:
    wb.Sheets(1).UsedRange.Offset(2).Copy
    With ws.Range("A" & Rows.Count).End(3)(2)
        .PasteSpecial Paste:=xlPasteValues
        .PasteSpecial Paste:=xlPasteComments
    End With
    ws.Columns.AutoFit
 
Upvote 0
Solution
OK can you replace the whole section I gave you last time from With to End With, and use this instead.

VBA Code:
    wb.Sheets(1).UsedRange.Offset(2).Copy
    With ws.Range("A" & Rows.Count).End(3)(2)
        .PasteSpecial Paste:=xlPasteValues
        .PasteSpecial Paste:=xlPasteComments
    End With
    ws.Columns.AutoFit
Hi Alex Blakenburg as it should be, thank you, have a nice day, from Denmark Klaus W
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,344
Members
452,638
Latest member
Oluwabukunmi

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