Keep value format the same

michelernqm

New Member
Joined
Jun 19, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Need help- when copying values from workbooks to destination sheet, need help with keeping the same format. Example F2472 is a %, I need the macro to write it as it is in the original sheets. My code below, not sure where or what to insert to force values to return the same. Thanks in advance.

VBA Code:
Sub t()
Dim fPath As String, fName As String, sh As Worksheet, wb As Workbook
Set sh = ThisWorkbook.Sheets("Summary")
fPath = ThisWorkbook.Path & "\"
fName = Dir(fPath & "*.xls*")
    Do While fName <> ""
        If fName <> ThisWorkbook.Name Then
            Set wb = Workbooks.Open(fPath & fName)
            On Error Resume Next
            With wb.Sheets("ALL")
                If Err.Number <> 9 Then
                    sh.Cells(Rows.Count, 1).End(xlUp)(2) = wb.Name
                    sh.Cells(Rows.Count, 1).End(xlUp).Offset(, 1) = wb.Sheets("ALL").Range("B2444").Value
                    sh.Cells(Rows.Count, 1).End(xlUp).Offset(, 2).Resize(, 1) = wb.Sheets("ALL").Application. _
                    Transpose(Range("F2472"))
                    sh.Cells(Rows.Count, 1).End(xlUp).Offset(, 3) = Application. _
                    Transpose(wb.Sheets("ALL").Range("E2472"))
                    sh.Cells(Rows.Count, 1).End(xlUp).Offset(, 4).Resize(, 1) = wb.Sheets("ALL").Application. _
                    Transpose(Range("D2472"))
                End If
                If Err.Number > 0 And Err.Number <> 9 Then
                    MsgBox "Error " & Err.Number & ":  " & Err.Description
                ElseIf Err.Number > 0 Then
                    MsgBox "Sheet 'list' not found in " & wb.Name, vbExclamation, "SHEET NOT FOUND"
                End If
            End With
            On Error GoTo 0
            Err.Clear
            wb.Close False
        End If
        fName = Dir
    Loop
End Sub
 
Last edited by a moderator:

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.
Maybe record a macro where you copy then paste special, values and number formats with option transpose. That should give you some inspiration.
 
Upvote 0
Solution
Well done, thank you for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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