Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default logical function template

Not usre where you are getting the error or what code you have changed. The
original code brought up a pop up window to allow you to select the file with
your original data. You didn't need to change it to book1.xls.

"SJay" wrote:

Yeah I forgot I'd changed that from the original. When I fixed that and ran
the macro the following box popped up:

Run-time error '438'
Object doesn't support this property or method

Let me know if this is a standard error and easy to fix. Cheers


"Bob Phillips" wrote:

That should be

Set OldBk = Workbooks.Open(Filename:=FileToOpen)


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"SJay" wrote in message
...
Hi Joel, thanks for your response. Based on your explanation, you've
definitely identified exactly what I want to do.

I'm pretty much a novice with Visual Basic, so I tried entering the code
and
it didn't work the first time. I think the problem is in the following
section:

'OPen Workbook
FileToOpen = Application _
.GetOpenBook1("Excel Files (*.xls), *.xls")
If FileToOpen = False Then
MsgBox ("Can't Open file - Exit sub")
Exit Sub
End If

Set OldBk = Workbooks.Open(Book1.xls:=FileToOpen)
Set OldSht = OldBk.Sheets("sheet1")

The code sequence above - Set OldBk =
Workbooks.Open(Book1.xls:=FileToOpen)
-was highlighted in red, so I'm not sure if that's where the program has
identified the error.

Is there anything basic that I'm missing here? e.g. do I need to type in
the
name of my workbook into the code or something like that?


"Joel" wrote:

The code copies columns A & B then checks if the Brands in column c
exists.
If it exists then it puts the number in column c, otherwise, it adds a
new
row and puts the Brand in column A and the number in column C.

Sub combinelist()

Set NewSht = ThisWorkbook.Sheets("Sheet1")

'OPen Workbook
FileToOpen = Application _
.GetOpenFilename("Excel Files (*.xls), *.xls")
If FileToOpen = False Then
MsgBox ("Can't Open file - Exit sub")
Exit Sub
End If

Set OldBk = Workbooks.Open(Filename:=FileToOpen)
Set OldSht = OldBk.Sheets("sheet1")

With OldSht
'copy columns A and B
.Columns("A:B").Copy _
Destination:=NewSht.Columns("A:B")
NewRow = NewSht.Range("A" & Rows.Count).End(xlUp).Row + 1

LastRow = .Range("C" & Rows.Count).End(xlUp).Row
For RowCount = 1 To LastRow
If .Range("C" & RowCount) < "" Then
Brand = .Range("C" & RowCount)
Number = .Range("D" & RowCount)

With NewSht
'check if brand exist already
Set c = .Columns("A").Find(what:=Brand, _
LookIn:=xlValues, lookat:=xlWhole)
If c Is Nothing Then
.Range("A" & NewRow) = Brand
.Range("C" & NewRow) = Number
NewRow = NewRow + 1
Else
.Range("C" & c.Row) = Number
End If

End With
End If
Next RowCount
End With
OldBk.Close savechanges:=False
End Sub


"SJay" wrote:

I have two different data sets with the following characteristics:

Data set 1: Brand names (e.g. Coca Cola) in Column A with an
accompanying
number in Column B.

Data set 2: Brand names in Column C with an accompanying number in
Column D.

The numbers which accompany each brand name are different. Some brands
are
listed in both data sets, and some are listed in one data set or the
other.

I want to create a list in which all the brands across both counts are
listed once in one column, with the accompanying number from both data
sets
in the corresponding cells.

Where a Brand is counted in one data set and not the other, it will
list the
number for the data set in which it was registered, and a zero for the
data
set where it was not counted. Where a brand is counted in both data
sets, it
will list both numbers next to the brand, cancelling out the need to
list the
brand name twice.

I can do all of the above by messing around with VLOOKUP and IF
functions,
but I want to try and create a template so that I can plug in two
different
data sets from multiple sources. Then, the worksheet will immediately
convert
the two counts into one list with the corresponding numbers from both
counts
associated with each brand.

I hope this made sense! Let me know if there's anything that can be
done.

Cheers,
SJay




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Logical function please Amin Excel Worksheet Functions 3 April 16th 10 09:44 AM
Help!!! - logical function for someone not very logical ECH123 Excel Worksheet Functions 3 May 11th 09 04:14 PM
Help with logical function PT New Users to Excel 2 February 22nd 08 02:13 AM
Help with logical function PT Excel Worksheet Functions 2 February 22nd 08 02:13 AM
logical function [email protected] Excel Worksheet Functions 4 July 27th 06 04:43 AM


All times are GMT +1. The time now is 07:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"