- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Reply to: Excel macro problem
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "Excel macro problem"
Collapse
-
Got there in the end with some butchery on Pondlifes script and bit's and pieces from everyone else. Thanks for the help everyone. First codeing of any kind i've done in years and first bit of VB ever
-
-
Aye it works I've done it in the past. Not a bad option if you hate VB but are compentent at SQL.Originally posted by thunderlizard View PostYou can pretend Excel is Access (well, sort of).
If you create named ranges on each of your 2 data sources, the Excel ODBC provider will see them as data tables. So if you create a DSN for your spreadsheet, you should then be able to query and join the 2 tables.
Leave a comment:
-
You can pretend Excel is Access (well, sort of).
If you create named ranges on each of your 2 data sources, the Excel ODBC provider will see them as data tables. So if you create a DSN for your spreadsheet, you should then be able to query and join the 2 tables.
You can even return the data back into the same spreadsheet: maybe using the MS Query tool that's built into Excel, or maybe using some ADO code sitting behind a user form or other macro.
I was reading a website a couple of weeks ago that explained this really well, but I'm darned if I can find it now.
Leave a comment:
-
OK then....
Sub fill_data()
Dim vArrayS1 As Variant
Dim vArrayS2 As Variant
Dim vArrayS3 As Variant
Dim S1Counter As Long
Dim S2Counter As Long
Dim lgCounter As Long
Dim lgCounter2 As Long
Dim strUsrid As String
Dim strCatid As String
Dim strCatid2 As String
Dim strFunctid As String
Dim lgOCounter As Long
dim intSheetNum as integer
S1Counter = Sheets(1).UsedRange.Rows.Count - 1
S2Counter = Sheets(2).UsedRange.Rows.Count - 1
ReDim vArrayS1(S1Counter, 1)
ReDim vArrayS2(S2Counter, 1)
lgOCounter = 1
'this could be one function but I couldn't be bothered
For lgCounter = 2 To S1Counter
vArrayS1(lgCounter - 2, 0) = Sheets(1).Cells(lgCounter, 1).Value
vArrayS1(lgCounter - 2, 0) = Sheets(1).Cells(lgCounter, 2).Value
Next lgCounter
For lgCounter = 2 To S2Counter
vArrayS2(lgCounter - 2, 0) = Sheets(2).Cells(lgCounter, 1).Value
vArrayS2(lgCounter - 2, 0) = Sheets(2).Cells(lgCounter, 2).Value
Next lgCounter
For lgCounter = 2 To S1Counter
strUsrid = vArrayS1(lgCounter, 0)
strCatid = vArrayS1(lgCounter, 1)
intsheetnum = 3
For lgCounter2 = 2 To S2Counter
strCatid2 = vArrayS2(lgCounter2, 0)
strFunctid = vArrayS2(lgCounter2, 1)
If strCatid = strFunctid Then
Sheets(3).Cells(lgOCounter, 1).Value = usrid
Sheets(3).Cells(lgOCounter, 2).Value = catid
Sheets(3).Cells(lgOCounter, 3).Value = functid
if lgocounter = 65000 then
lgocounter = 1
sheets.add
intsheetnum = intsheetnum+1
else
lgOCounter = lgOCounter + 1
End If
end if
Next lgCounter2
Next lgCounter
End Sub
So when the row count on the output sheet hit 65000 it adds a new sheet ad starts from 1 again
Leave a comment:
-
Speed isnt so much the problem as much as the fact that the combination of the two sheets will exceed the hard limit on numbers of rows in excel. Hence the multiple sheet idea.
Leave a comment:
-
this is probably wrong as i had no data to test it on..................
Sub fill_data()
Dim vArrayS1 As Variant
Dim vArrayS2 As Variant
Dim vArrayS3 As Variant
Dim S1Counter As Long
Dim S2Counter As Long
Dim lgCounter As Long
Dim lgCounter2 As Long
Dim strUsrid As String
Dim strCatid As String
Dim strCatid2 As String
Dim strFunctid As String
Dim lgOCounter As Long
S1Counter = Sheets(1).UsedRange.Rows.Count - 1
S2Counter = Sheets(2).UsedRange.Rows.Count - 1
ReDim vArrayS1(S1Counter, 1)
ReDim vArrayS2(S2Counter, 1)
lgOCounter = 1
'this could be one function but I couldn't be bothered
For lgCounter = 2 To S1Counter
vArrayS1(lgCounter - 2, 0) = Sheets(1).Cells(lgCounter, 1).Value
vArrayS1(lgCounter - 2, 0) = Sheets(1).Cells(lgCounter, 2).Value
Next lgCounter
For lgCounter = 2 To S2Counter
vArrayS2(lgCounter - 2, 0) = Sheets(2).Cells(lgCounter, 1).Value
vArrayS2(lgCounter - 2, 0) = Sheets(2).Cells(lgCounter, 2).Value
Next lgCounter
For lgCounter = 2 To S1Counter
strUsrid = vArrayS1(lgCounter, 0)
strCatid = vArrayS1(lgCounter, 1)
For lgCounter2 = 2 To S2Counter
strCatid2 = vArrayS2(lgCounter2, 0)
strFunctid = vArrayS2(lgCounter2, 1)
If strCatid = strFunctid Then
Sheets(3).Cells(lgOCounter, 1).Value = usrid
Sheets(3).Cells(lgOCounter, 2).Value = catid
Sheets(3).Cells(lgOCounter, 3).Value = functid
lgOCounter = lgOCounter + 1
End If
Next lgCounter2
Next lgCounter
End Sub
Leave a comment:
-
If they are that big you might want to read them into 2 massive arrays so that it speeds up - Excel is painfull when you have to go cell by cell
Leave a comment:
-
Pondlife, that would be spot on but for the fact that the two sheets contain 12746 and 15115 records respectivly. If I restict the number of rows read, rather than letting it try and go to the end it works just fine.
With a bit of jiggery pokery I think I can make it work by doing it by user ID from the 1st sheet and searching for the matching categories in the second sheet then creating a new sheet for each user ID ( 207 in total ). Back to the VB books.
Leave a comment:
-
If the used rows in sheet1 x used rows in sheet2 < 65K then populate sheet 3 with the following and filter on col1
Code:Sub fill_data() lastrec = 1 i = 2 Do Until i = Sheet1.UsedRange.Rows.Count + 1 usrid = Sheet1.Cells(i, 1).Value catid = Sheet1.Cells(i, 2).Value j = 2 Do Until j = Sheet2.UsedRange.Rows.Count + 1 catid2 = Sheet2.Cells(j, 1).Value functid = Sheet2.Cells(j, 2).Value If catid = catid2 And functid <> "" Then Sheet3.Cells(lastrec, 1).Value = usrid Sheet3.Cells(lastrec, 2).Value = catid Sheet3.Cells(lastrec, 3).Value = functid lastrec = lastrec + 1 End If j = j + 1 Loop i = i + 1 Loop End Sub
Leave a comment:
-
build a third column
=b1 & a1
this will concatenate the two fields then sort.
all your func1 will be grouped together
a pooey solution I agree
Leave a comment:
-
Your client doesn't have Access licences??!! Are they using Office Home edition or something??
Anyway, if TonyEnglish's solution isn;t any good for you, I think this might actually be possible without using any VB, just some clever functions like OFFSET and FIND etc... So long as your data is sorted in order
Leave a comment:
-
Thanks for the replies guys, Access isn't an option unfortunately. Client doesnt want to buy a license just for this job
Tony, I've PM'd you.
Leave a comment:
-
are you trying to have 2 list boxes - the contents of the second depending on the value in the first? If so I have something which you might find useful - in Excel
Send me a pm with youe mail in it and I'll send it you
I nicked it from http://www.brainbell.com/tutorials/m...other_List.htm
as I had a similar problem a while ago. The example in the page above doesn't quite work but I managed to fix it.
Leave a comment:
-
Yes, its possible but maybe not filter as AFAIK that allows 2 criteria.
If it was me I'd upload it to Access and SQL it.
Leave a comment:
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers

Leave a comment: