Forum Discussion
Samarth1508
Mar 03, 2023Copper Contributor
VBA code to get column data from another worksheet.
Hi All, I am using below code to get column data from another worksheet, but the below code is working for full column, and I don't want to replace my Heder data of another sheet. can someone...
- May 25, 2023
Hi,
I have a client who has his frontend and backend always in the same folder but sometimes copies both files to different computers and thus different paths. So we relink the backend tables every time he starts the application to the folder path of the frontend. Your problem seems similar and could probably be solved = automated with a similar technique:
1. Create a new VBA module in the frontend.
2. Copy this function into the module:
Public Function fctLinkedTablePaths() On Error GoTo myError Dim db As DAO.Database Dim tdf As DAO.TableDef Dim strDbFile As String Set db = CurrentDb For Each tdf In db.TableDefs If tdf.Connect <> "" Then strDbFile = Mid(tdf.Connect, InStrRev(tdf.Connect, "\")) tdf.Connect = ";database=" & CurrentProject.Path & strDbFile tdf.RefreshLink End If Next tdf myExit: Exit Function myError: Select Case Err.Number Case 9999 'trap specific errors Case Else MsgBox "Exception No. " & Err.Number & ". " & Err.Description Resume myExit End Select End Function
3. Create a new macro called: AutoExec
4. In the macro choose the action: RunCode
and as Function Name: =fctLinkedTablePaths()
Servus
Karl
****************
Access Bug Trackers
Access News
Access DevCon
FikturFox
Mar 03, 2023Brass Contributor
Replace "B1:B" to "B2:B" in your code.
B1, I assume is where the header is. So move 1 row down making it B2.
B1, I assume is where the header is. So move 1 row down making it B2.
- Samarth1508Mar 03, 2023Copper ContributorTried this one also but code is transferring data to same range only.
Means suppose I have update Sheet1.Range("B2:B") & Sheet2.Range("B2:B") then code works fine, but If I Update Sheet1.Range("B2:B") & Sheet2.Range("B8:B") then code is not transferring data to same range.- FikturFoxMar 03, 2023Brass ContributorThat's because they don't have the same range. You have to adjust your range in Sheet2.
ie Sheet2.range("b8:b" & lr +7)- Samarth1508Mar 03, 2023Copper Contributor
Hi FikturFox
It is working fine, I have done small change insted of +7 it is woking with +6.
Sub Select_Data()
Dim lr As Long
lr = Sheet1.Range("B" & Rows.Count).End(xlUp).Row
If Not IsEmpty(Sheet1.Range("B2:B" & lr).Value) Then Sheet2.Range("B8:B" & lr+6).Value = Sheet1.Range("B2:B" & lr).Value
End Sub