473,386 Members | 1,621 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,386 software developers and data experts.

Edexcel - Miscrosoft Visual Basic help

118 100+
In Excel I have a "Home" page with cells in which you insert:
Customer Name
Customer Type (drop down type for 'Standard', 'Business man' and 'Tour Group'.)
Nights Staying
Room Number (Drop Down for room numbers; from Page "Customers" in which the numbers are in a named range)
and Date Of Arrival

I have a basic VB code to copy the details from the Home page to the Customers page. However, at the moment it only copies them to one place in the Customers page.

How would I link them to the cells next to the named range (Customers page) where the number is the same as in the drop down 'Room Number'.

So for example someone selects room '7' in the drop down list, then writes their details. How would I get it so, when they press add (run the Macro) the details are pasted (or moved to) in, say, cell C13 which is next to number 7 from the range.. and therefore the same for every/any number that is in the drop-down, goes to the same number in the Customers page.

I hope that makes sense.

Sam
Mar 26 '07 #1
2 1112
helraizer1
118 100+
So far I have written:

Expand|Select|Wrap|Line Numbers
  1.  If Range("G28").Value = "1" Then
  2.     Sheets("Home").Select
  3.     Range("G19:I19").Select
  4.     Selection.Copy
  5.     Sheets("Customers").Select
  6.     Range("C7").Select
  7.     Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
  8.     xlNone, SkipBlanks:=False, Transpose:=False
  9.     Sheets("Home").Select
  10.     Range("G22").Select
  11.     Selection.Copy
  12.     Sheets("Customers").Select
  13.     Range("F7").Select
  14.     Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
  15.     xlNone, SkipBlanks:=False, Transpose:=False
  16.     Sheets("Home").Select
  17.     Range("G25").Select
  18.     Selection.Copy
  19.     Sheets("Customers").Select
  20.     Range("J7").Select
  21.     Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
  22.     xlNone, SkipBlanks:=False, Transpose:=False
  23.     Sheets("Home").Select
  24.     Range("G31").Select
  25.     Selection.Copy
  26.     Sheets("Customers").Select
  27.     Range("H7").Select
  28.     Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
  29.     xlNone, SkipBlanks:=False, Transpose:=False
  30.         Exit Sub
  31.     End If
  32.  
So far this works but since there are 50 'rooms' + 7 other rooms in the drop down.. I will have to do this code 57 times over. Is there an easier way to get the number to correspond with the same number in the next page (details in first post)?

Thanks,

Sam
Mar 26 '07 #2
Killer42
8,435 Expert 8TB
While there are probably more elegant ways to achieve this, I'm not all that familiar with using Excel features from VBA. A simple brute-force method would be to use a FOR loop to run through the range of cells, and handle each one in turn.

The section of code which would have been repeated 57 times is then required only once, either within the loop of in a separate Sub or Function which you call from inside the loop.
Mar 27 '07 #3

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

Similar topics

2
by: AK | last post by:
I don't want any part of the previous discussion on Visual Basic versus Visual Basic.Net. My query is about using Visual Basic for Applications; and whether it is better to use Visual Basic 6 or...
2
by: Anil Sahai | last post by:
I installed Visual Studio Version 6.0 with Visual Basic and Visual C++ etc. When I tried to invoke Help in Visual BASIC, it said that I should install MSDN. I installed MSDN using the MSDN library...
2
by: janice_2k | last post by:
Dear Sir/Mdm, I am writing this on behalf of my company. We bought the Visual Studio .NET Enterprise version but currently we need to use Visual Basic 6 for a small development. We are not able to...
2
by: Ralph | last post by:
I used to have Visual Basic .net std. 2003 installed on WinXP SP1A. But I found it too hard to upgrade WinXP to SP2. Now, I do have WinXP SP2 installed, but I am having problems installing...
2
by: frossberg | last post by:
Hello! I tried to install the Visual Basic.NET Resource Kit (http://msdn.microsoft.com/vbasic/vbrkit/) but obviously something went very wrong and now it sems impossible both to repair and to...
5
by: Microsoft | last post by:
Hi, I have Visual Basic .net 2003 (Standard Edition) & SQL Server 2000 Developer Edition. When trying to create a connection in the server explorer from the .net IDE I get a number of problems;...
2
by: elnahrawi | last post by:
Download ebook http://books-download.com/?Book=1487-Visual+Basic+2005+Jumpstart Okay, all you VB6 developers--time's up. As of March 2005, Microsoft no longer supports this version of Visual...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
1
by: qwer | last post by:
import data from vb.net to miscrosoft access -------------------------------------------------------------------------------- Hi, im trying to import and store data from visual basic.net to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.