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

Assigning a variable value as an Excel cell's address

Hi all

I am trying a project in vb6
I have 10 command buttons and 10 text boxes with some data holded
i transferred all the data as a complete record to an Excel file via vb6 code

tell you bit clearly with 4 controls i used in my work
my 1st command button is
Caption : BooksNames
Name : cmdTBooksNames

my 2nd command button is
Caption : No of books
Name : cmdTNoOfBooks

my 1st text box is
Name : txtBooksNames
Text : ""

my 2nd text box is
Name : txtNoOfBooks

when i execute my program, the user will give 2 inputs

i created the code in vb6 to pass those values to excel sheet
Also i have coded the excel sheet via vb6 to locate the received values in specified cells like the code follows

**************************************
oXLSheet.Range("A1") = TBksNames

oXLSheet.Range("B1") = BksNames

oXLSheet.Range("A2") = TNoOfBks

oXLSheet.Range("B2") = NoOfBks
************************************************** **
For example,Now i have the values from the range A1 to B2
Everything going good

But when i execute my program once again, the vaues which i am giving for the second time replacing the existing data

So,i googled and i found the following snippet to find the first unused row in the excel sheet so that i can find the activated row to transfer my second record

************************************************** **
Set oXLRange = oXLSheet.UsedRange

oXLRange.SpecialCells(xlCellTypeLastCell).Activate
newStartingRow = oXLApp.ActiveCell.Row + 1
newStartingCell = "A" & newStartingRow

oXLApp.Range(newStartingCell).Activate
************************************************** ***

But the problem here is , I have to code again by changing the cell's address,like
************************************************** *
oXLSheet.Range("A3") = TBksNames

oXLSheet.Range("B3") = BksNames

oXLSheet.Range("A4") = TNoOfBks

oXLSheet.Range("B4") = NoOfBks

************************************************** *
It becomes more complicated if i want to add 10 records per day

I feel frustrated to code again
is there any possibities to duplicate the activated cell address as "A1:B2",but saving the record next to the existing record automatically

please i neeed some idea

help me out

thank you
Apr 21 '12 #1
2 7212
Guido Geurs
767 Expert 512MB
Is this the same problem as in your call:
"adding a new record to an existing record in a single Excel sheet
" ?
If so, no need to use the cell address.
PS:
If you want to set the cell address, use a var like:
Expand|Select|Wrap|Line Numbers
  1. dim CELLADDRESS as string
  2. CELLADDRESS = "A1"
  3. Range(CELLADDRESS) = textbox.text
Apr 21 '12 #2
Stewart Ross
2,545 Expert Mod 2GB
You can use the Cells method of the Excel range to refer to a specific cell using numeric variables to refer to the row and column concerned. I use your worksheet variable oXLSheet in the examples below, but any worksheet object variable (or the .Activesheet method of the Excel application object) could be used instead.

oXLSheet.Cells(1,1) is cell A1, .Cells(1, 2) is A2, and so on.

If you are processing multiple rows you can use the cells method to make it a lot easier to refer to specific elements without having to use the A, B C column identifiers.

As a simple example, the following loop will set the values of cells A1 to G3 to 0. Column A is the first column, column G is the seventh, so we need to loop through rows 1 to 3 and columns 1 to 7 to set the individual cells to 0:

Expand|Select|Wrap|Line Numbers
  1. Const cRows = 7
  2. Const cCols = 3
  3. Dim intRow as Integer
  4. Dim intCol as Integer
  5. For intRow = 1 to cRows
  6.   For intCol = 1 to cCols
  7.     oXLSheet.Cells(intRow, intCol) = 0
  8.   Next
  9. Next
No need to use the Range("A1") notation at all if you use the Cells method instead.

A range spanning more than one cell can also be defined specifically using the Cells method, but it needs the With notation to make it easier to read. The exemplar below sets a range variable to the span of cells between A1 and G3, again just as an example.

Expand|Select|Wrap|Line Numbers
  1. Dim oRange as Range
  2. With oXLSheet
  3.   Set oRange = .Range(.Cells(1, 1), .Cells(3, 7))
  4. End With
-Stewart
Apr 21 '12 #3

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

Similar topics

11
by: Pete Mahoney | last post by:
I am currently working on an ASP page where I create a lot of different check boxes. I have some checkboxes that are Windows platforms and some that are solaris platforms. I want a control...
2
by: Scott | last post by:
I need to write a function that copies variables to fields. I've used an array and loop because it's neater than writing a similar sentence out 10 times. var myString = new...
5
by: GB | last post by:
Hello: In my MS Access project I have two objects - my form and my report. I need to pass variable value from Command_click procedure of my form to Report_open procedure of my report. How can I...
3
by: Shapper | last post by:
Hello, I have an aspx.vb code with a function. In this function I need to check if a variable is a valid email address. Something like: address@domain.extension How can I do this? Thanks,
8
by: John Brock | last post by:
I am creating an Excel workbook using VB.NET, and have run into a problem. Excel at times insists on reformatting data that I enter into cells, e.g., converting "01234" to "1234", and this screws...
10
by: Ashish | last post by:
Hi I am new to C I have one query.... can i store a value on a given memory location in C say for example i want to store an integer value 10 at location 0X100000. how can i do it in C... if...
6
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I...
1
by: Vinod | last post by:
Hi, In VC8 project, I am having a struct which is having a char* variable. Now I am creating a 3 elements array object for the struct. I send the base address of the object using VARIANT to a...
3
by: squash | last post by:
I have spent two hours trying to make sense of this script, called crazy.php. The output should be nothing because $cookie_password is nowhere defined in this script, correct? But it actually...
3
by: Vols | last post by:
void f (char *a) { a++; } int main (void) { char a = "abc";// or char *a = "abc"; f (a); puts (a);
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...

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.