sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
This worksheet that I'm copying has a couple checkboxes on there, like "CheckBox1" and "CheckBox2". These are the type that are added using the Developer Tab for forms. The master file I'm copying to has columns called "In-Ground" and "Holeless", that are respective to the two checkboxes. Somehow, I need to find a way to show the word "Yes" under one of the two destination file column headings based on which of the two checkboxes is checked in the file I'm extracting the data from. I have a separate issue as well regarding getting this code to loop through all the worksheets in the source workbook that opens and grab the same information from each, regardless of worksheet names in the workbook. I can put that last part in a different post if I cannot find an answer on my own. I appreciate any help I can get on this one.
VBA Code:
Sub ImportInfo()
Dim sPath As String 'path of folder containing info
Dim sFileName As String '
Dim wsSummary As Worksheet 'worksheet to paste data to in this workbook
Dim wsData As Worksheet 'sheet with data to copy
Dim wb As Workbook 'workbooks to loop thorugh
Dim nr As Long 'next row to add the data
'Get the worksheet to add the info to
Set wsSummary = ThisWorkbook.Worksheets("Sheet1")
'first row is 4
nr = 2
sPath = "C:\Documents\Projects\" '[COLOR=#ff0000][B]Change as required[/B][/COLOR]
sFileName = Dir(sPath & "*.xlsm")
Do While sFileName <> ""
'open workbook
Set wb = Workbooks.Open(Filename:=sPath & sFileName, ReadOnly:=True)
'get the sheet to copy from
Set wsData = wb.Sheets("DEM Release Form")
'get the data
wsSummary.Range("A" & nr).Value = wsData.Range("C3").Value
wsSummary.Range("B" & nr).Value = wsData.Range("B8").Value
wsSummary.Range("C" & nr).Value = wsData.Range("F8").Value
wsSummary.Range("D" & nr).Value = wsData.Range("C10").Value
wsSummary.Range("E" & nr).Value = wsData.Range("G10").Value
wsSummary.Range("F" & nr).Value = wsData.Range("B9").Value
wsSummary.Range("G" & nr).Value = wsData.Range("I9").Value
'get next row
nr = nr + 1
'close the workbook
wb.Close
'get next workbook name
sFileName = Dir
Loop
End Sub