Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default error in this code

Hi,
I want to read entered text and do action as follows.But I am getting
error ,in Range().Plz help me to rectify.
getting error at set range line and in the For loop.Code is as follows


Private Sub Copyformula_Click()

Dim str As String
Dim i, x As Integer


strFrom = Mid(UCase(Trim(TxtFrom.Text)), 1, 2)
strTo = Mid(UCase(Trim(TxtTo.Text)), 1, 2)

intFrom = CInt(Mid(Trim(TxtFrom.Text), 3, 2))
intTo = CInt(Mid(Trim(TxtTo.Text), 3, 2))

strModule = UCase(Trim(TxtModule.Text))

Set Range = ActiveSheet.Range(""" & UCase(Trim(TxtFrom.Text) & ":" &
UCase(Trim(TxtTo.Text))& """)

If Not Range.HasFormula Then

'On Error Resume Next

If MsgBox("Those cells contains formula,Do you want to replace ?",
"Check", vbYesNo) = vbYes Then

'On Error Resume Next

For i = intFrom To intTo


ActiveSheet.Range(""" & strFrom & """ & i).Formula =
"=COUNTIF(D17:D2000,""" & ActiveSheet.Range(""" & strModule & """ &
i).Text & """)"


Next i


ActiveSheet.Range(""" & strFrom & """ & intTo + 1).Formula =
"=SUM(" & UCase(Trim(TxtFrom.Text)) & ":" & UCase(Trim(TxtTo.Text)) & "
)"

Else

Exit Sub

End If

'Else

'For x = intFrom To intTo


'ActiveSheet.Range(""" & strFrom & """ & x).Formula =
"=COUNTIF(D17:D2000,""" & ActiveSheet.Range(""" & strModule & """ &
x).Text & """)"


'Next x


'ActiveSheet.Range(""" & strFrom & """ & intTo + 1).Formula =
"=SUM(" & UCase(Trim(TxtFrom.Text)) & ":" & UCase(Trim(TxtTo.Text)) & "
)"
'Range("AJ" & i - 1).Cells.Formula
'"=COUNTIF(D17:D2000,""" & Range("AI" & i).Text & """)"
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 138
Default error in this code

People in this NG are exceptionally nice, but if you through code at them
and expect them to find out what it does and why it doesn't work, you are
probably asking too much. Besides: Many of your variables are neither
defined nor explained.

Joerg


wrote in message
ups.com...
Hi,
I want to read entered text and do action as follows.But I am getting
error ,in Range().Plz help me to rectify.
getting error at set range line and in the For loop.Code is as follows


Private Sub Copyformula_Click()

Dim str As String
Dim i, x As Integer


strFrom = Mid(UCase(Trim(TxtFrom.Text)), 1, 2)
strTo = Mid(UCase(Trim(TxtTo.Text)), 1, 2)

intFrom = CInt(Mid(Trim(TxtFrom.Text), 3, 2))
intTo = CInt(Mid(Trim(TxtTo.Text), 3, 2))

strModule = UCase(Trim(TxtModule.Text))

Set Range = ActiveSheet.Range(""" & UCase(Trim(TxtFrom.Text) & ":" &
UCase(Trim(TxtTo.Text))& """)

If Not Range.HasFormula Then

'On Error Resume Next

If MsgBox("Those cells contains formula,Do you want to replace ?",
"Check", vbYesNo) = vbYes Then

'On Error Resume Next

For i = intFrom To intTo


ActiveSheet.Range(""" & strFrom & """ & i).Formula =
"=COUNTIF(D17:D2000,""" & ActiveSheet.Range(""" & strModule & """ &
i).Text & """)"


Next i


ActiveSheet.Range(""" & strFrom & """ & intTo + 1).Formula =
"=SUM(" & UCase(Trim(TxtFrom.Text)) & ":" & UCase(Trim(TxtTo.Text)) & "
)"

Else

Exit Sub

End If

'Else

'For x = intFrom To intTo


'ActiveSheet.Range(""" & strFrom & """ & x).Formula =
"=COUNTIF(D17:D2000,""" & ActiveSheet.Range(""" & strModule & """ &
x).Text & """)"


'Next x


'ActiveSheet.Range(""" & strFrom & """ & intTo + 1).Formula =
"=SUM(" & UCase(Trim(TxtFrom.Text)) & ":" & UCase(Trim(TxtTo.Text)) & "
)"
'Range("AJ" & i - 1).Cells.Formula
'"=COUNTIF(D17:D2000,""" & Range("AI" & i).Text & """)"
End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default error in this code


Joerg wrote:
People in this NG are exceptionally nice, but if you through code at them
and expect them to find out what it does and why it doesn't work, you are
probably asking too much. Besides: Many of your variables are neither
defined nor explained.

Joerg


wrote in message
ups.com...
Hi,
I want to read entered text and do action as follows.But I am getting
error ,in Range().Plz help me to rectify.
getting error at set range line and in the For loop.Code is as follows


Private Sub Copyformula_Click()

Dim str As String
Dim i, x As Integer


strFrom = Mid(UCase(Trim(TxtFrom.Text)), 1, 2)
strTo = Mid(UCase(Trim(TxtTo.Text)), 1, 2)

intFrom = CInt(Mid(Trim(TxtFrom.Text), 3, 2))
intTo = CInt(Mid(Trim(TxtTo.Text), 3, 2))

strModule = UCase(Trim(TxtModule.Text))

Set Range = ActiveSheet.Range(""" & UCase(Trim(TxtFrom.Text) & ":" &
UCase(Trim(TxtTo.Text))& """)

If Not Range.HasFormula Then

'On Error Resume Next

If MsgBox("Those cells contains formula,Do you want to replace ?",
"Check", vbYesNo) = vbYes Then

'On Error Resume Next

For i = intFrom To intTo


ActiveSheet.Range(""" & strFrom & """ & i).Formula =
"=COUNTIF(D17:D2000,""" & ActiveSheet.Range(""" & strModule & """ &
i).Text & """)"


Next i


ActiveSheet.Range(""" & strFrom & """ & intTo + 1).Formula =
"=SUM(" & UCase(Trim(TxtFrom.Text)) & ":" & UCase(Trim(TxtTo.Text)) & "
)"

Else

Exit Sub

End If

'Else

'For x = intFrom To intTo


'ActiveSheet.Range(""" & strFrom & """ & x).Formula =
"=COUNTIF(D17:D2000,""" & ActiveSheet.Range(""" & strModule & """ &
x).Text & """)"


'Next x


'ActiveSheet.Range(""" & strFrom & """ & intTo + 1).Formula =
"=SUM(" & UCase(Trim(TxtFrom.Text)) & ":" & UCase(Trim(TxtTo.Text)) & "
)"
'Range("AJ" & i - 1).Cells.Formula
'"=COUNTIF(D17:D2000,""" & Range("AI" & i).Text & """)"
End If

End Sub


Thanks for your reply.But I just wanted to know the cause of the error
,where I used Range().For reference I had given a part of my code,I
thought it will be more comprehensable.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 Questions John Calder New Users to Excel 18 August 24th 06 04:17 AM
code not unique find latest date Barbara Wiseman Excel Discussion (Misc queries) 3 December 11th 05 08:50 AM
VLOOKUP for Zip Code Ranges JerseyJR Excel Worksheet Functions 2 September 6th 05 06:37 PM
Conform a total to a list of results? xmaveric Excel Discussion (Misc queries) 1 August 21st 05 07:22 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM


All times are GMT +1. The time now is 03:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"