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 2 1112
So far I have written: -
If Range("G28").Value = "1" Then
-
Sheets("Home").Select
-
Range("G19:I19").Select
-
Selection.Copy
-
Sheets("Customers").Select
-
Range("C7").Select
-
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
-
xlNone, SkipBlanks:=False, Transpose:=False
-
Sheets("Home").Select
-
Range("G22").Select
-
Selection.Copy
-
Sheets("Customers").Select
-
Range("F7").Select
-
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
-
xlNone, SkipBlanks:=False, Transpose:=False
-
Sheets("Home").Select
-
Range("G25").Select
-
Selection.Copy
-
Sheets("Customers").Select
-
Range("J7").Select
-
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
-
xlNone, SkipBlanks:=False, Transpose:=False
-
Sheets("Home").Select
-
Range("G31").Select
-
Selection.Copy
-
Sheets("Customers").Select
-
Range("H7").Select
-
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
-
xlNone, SkipBlanks:=False, Transpose:=False
-
Exit Sub
-
End If
-
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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;...
|
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...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
| |