commandbutton on workbook assistance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I've dropped a commandbutton onto a work book. The button collects data from
that work book when clicked and opens a different workbook to apply the data
collected on to the new workbook. Alls good until I program a range/cell I
want the data dumped into when I get an error 1004 message. The program still
seems to be pointing at the first workbook. Any ideas how I get it to focus
on the new workbook?
 
Hi Laughing Gravy,

Try posting your problematic code.

However, you can almost certainly resolve your
problem by explicitly qualifying your ranges.
 
Try using workbook objects to make it easier to designate ranges. For
instance:

dim collectWB as Workbook, applyWB as Workbook
set collectWB = ThisWorkbook
'....collect data, etc
set applyWB = Workbooks.Open Filename:=(your file path here)

Then you can reference ranges using these workbook objects without having to
switch back and forth. For example, if you wanted to put the result into A1
on a sheet named "Total", you could use:

applyWB.sheets("Total").range("a1").value = result
'change this variable to work for you

Hope this helps.
Pflugs

laughing gravy said:
Hi

I've dropped a commandbutton onto a work book. The button collects data from
that work book when clicked and opens a different workbook to apply the data
collected on to the new workbook. Alls good until I program a range/cell I
want the data dumped into when I get an error 1004 message. The program still
seems to be pointing at the first workbook. Any ideas how I get it to focus
 
aha. Your a star.

thks

Pflugs said:
Try using workbook objects to make it easier to designate ranges. For
instance:

dim collectWB as Workbook, applyWB as Workbook
set collectWB = ThisWorkbook
'....collect data, etc
set applyWB = Workbooks.Open Filename:=(your file path here)

Then you can reference ranges using these workbook objects without having to
switch back and forth. For example, if you wanted to put the result into A1
on a sheet named "Total", you could use:

applyWB.sheets("Total").range("a1").value = result
'change this variable to work for you

Hope this helps.
Pflugs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top