473,395 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Excel VBA : Loop Sheets that meets the value in the range

wassup
34
Hey Guys,

Good Morning. I have probelm here.

I have 2 workbooks, 1 is Master.xls (my format to collect all the data), another 1 is Machine.xls (data collect from).

Inside Master.Range("B3:B5") have a data (etc: Line1, Line2, Line3), Machine.xls have a few sheets (etc: Line1, Line2, Line3....Line10).

Now my concern is I want the macro loop Master.Range("B3:B5") , if Master.Range = Line1 then it will loop Machine.xls untill found the sheets name is Line1 then collect data from it. It will loop Master.Range("B3:B5") untill equal to blank.

Thanks for your advice.
Jun 23 '08 #1
2 4466
kadghar
1,295 Expert 1GB
with a couple of IFS/THEN/ELSE and FOR/NEXT it can be done. To make reference to the workbooks, you can use their name or their index (the order they were open)

Check this little example:

Expand|Select|Wrap|Line Numbers
  1. If workbooks("myBook1").worksheets("sheet1).range("B1") = workbooks("myBook2").worksheets("sheet1).range("B1") then
  2. workbooks("myBook1").worksheets("sheet2).range("A4") = "Hello World"
  3. else
  4. workbooks("myBook2").worksheets("sheet2).range("C4") = "Goodbye Cruel World"
  5. end if
You can use Indexes or CELLS to put anything into a loop, eg:

Expand|Select|Wrap|Line Numbers
  1.  for i = 1 to 5
  2.     workbooks("myBook1").worksheets(i) = "Hello World"
  3. next
and you can always check the content or use the END method to go to the blank space, eg:

Expand|Select|Wrap|Line Numbers
  1. i=1
  2. do
  3.     i=i+1
  4. loop until cells(i,1) = ""
HTH
Jun 23 '08 #2
wassup
34
with a couple of IFS/THEN/ELSE and FOR/NEXT it can be done. To make reference to the workbooks, you can use their name or their index (the order they were open)

Check this little example:

Expand|Select|Wrap|Line Numbers
  1. If workbooks("myBook1").worksheets("sheet1).range("B1") = workbooks("myBook2").worksheets("sheet1).range("B1") then
  2. workbooks("myBook1").worksheets("sheet2).range("A4") = "Hello World"
  3. else
  4. workbooks("myBook2").worksheets("sheet2).range("C4") = "Goodbye Cruel World"
  5. end if
You can use Indexes or CELLS to put anything into a loop, eg:

Expand|Select|Wrap|Line Numbers
  1.  for i = 1 to 5
  2.     workbooks("myBook1").worksheets(i) = "Hello World"
  3. next
and you can always check the content or use the END method to go to the blank space, eg:

Expand|Select|Wrap|Line Numbers
  1. i=1
  2. do
  3.     i=i+1
  4. loop until cells(i,1) = ""
HTH
Thanks kadghar,

Its make me many confusing because to many For, Do, Loop.... but I have done it. Have a nice day.
Jun 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
1
by: RickH | last post by:
..Cells(1,y).GetType ownly shows instead of .Value, .Copy, etc. The code below is derived from samples, it should work, but I've messed up somewhere... Imports System.Windows.Forms Imports...
3
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to...
11
by: bbasberg | last post by:
Hello, I have been struggling with this problem for DAYS and have googled my heart out as well as reading any books I could get my hands on but I cannot find any specific references to my problem....
4
by: keithsimpson3973 | last post by:
Hi. I am trying build an array in vb applications for excel. I am posting the code for what I am trying to write. Any help would be appreciated greatly.. Sheets("C16-M-001").Select ...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
4
by: =?Utf-8?B?Um9iZXJ0?= | last post by:
I am opening an Excel Workbook from C# (VS2005) and I need to get a value from a Spreadsheet before closing the C# application. Does anyone know if this can be done? Here is the code to open the...
0
by: acarrazco | last post by:
Hello, I am totaly new to VBA and I'm trying to modify a macro that was given to me but it doesn't seem to be working. I'm trying to extract data from three excel spreadsheets, put it into a combined...
12
by: TARHEELS721 | last post by:
I am trying to send the results of a query that runs when I click a button on my form that is based on a parameter query. The code runs without any errors but nothing is exported into my excel...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.