मैं एक यूडीएफ का उपयोग कर रहा हूं जो मूल रूप से एक vlookup सरलीकृत है। कोड यहाँ है:
Function SUELDOBASICO(Columna As Integer) As Double
SUELDOBASICO = Application.WorksheetFunction.VLookup(Application.Caller.Parent.Cells(Application.Caller.Row, 3), Application.Caller.Parent.Parent.Sheets("Escalas Salariales").Range("A3:DJ23"), Columna, False)
End Function
मैंने देखा है कि कभी-कभी चादरों की प्रतिलिपि करते समय (उसी कार्यपुस्तिका के भीतर), मुझे एक मिलता है #VALUE
त्रुटि। यदि मैं एक्सेल में सेल को "संपादित" करता हूं, तो कुछ भी नहीं बदल रहा हूं, बस इसका उपयोग कर रहा हूं F2
तथा Enter
, त्रुटि गायब हो जाती है। यह तब होता था जब खिड़कियां बदलती थीं (फ़ायरफ़ॉक्स में, और एक्सेल पर वापस, उदाहरण के लिए)। यही कारण है कि मैंने इस्तेमाल किया Caller
तथा Parent
कोड में बहुत कुछ। कभी-कभी चादरों की प्रतिलिपि बनाते समय, यह लगभग पूरी तरह से तय किया जाता है। मुझे त्रुटि का स्रोत नहीं मिल रहा है। कृपया मदद करें।
उत्तर:
उत्तर № 1 के लिए 1मुझे पता है कि यह आपका सटीक प्रश्न नहीं है, लेकिन, यदि संभव हो, तो मैं सुझाव देता हूं कि वीबीए से पूरी तरह से बचें, अगर यह एक विकल्प है और अपना फॉर्मूला निम्नानुसार लिखता है:
=VLOOKUP(INDIRECT("C"&ROW()),"Escalas Salariales"!$A$3:$DJ$23,XXXXX,false)
तथा XXXXX
आपके जैसा ही हो सकता है Columna
वर्तमान में चर।
यह आपके कोड को आवश्यकतानुसार काम करने की गारंटी देगा।
टिप्पणियों में चर्चा की गई और इस काम को सुनिश्चित करने के लिए मेरी पूरी कोशिश करने का प्रयास करने के बाद, मुझे वास्तव में आपके कोड के साथ कुछ भी गलत नहीं दिख रहा है और मैं बस यह सोच रहा हूं कि इसका कुछ संबंध हो सकता है Application.Caller
.
जब इस तरह की बात मेरे साथ होती है, तो मैं डीबगर का उपयोग करने के लिए अपनी पूरी कोशिश करता हूं ताकि यह पता लगाया जा सके कि - आमतौर पर इसमें शामिल होता है Stop
कोड में कदम उठाने में सक्षम होने के लिए बयान और देखें कि क्या हुआ या Debug.Print Err.Description
संदेश की तरह।
किसी भी तरह से, मैंने प्रत्येक भाग को तोड़ने की कोशिश की, इसलिए, कम से कम आप देख सकते हैं कि समस्या कहां से आती है। ऐसा करने के लिए, मैंने आपके फ़ंक्शन को फिर से काम किया (कुछ प्रमुख ओवरकिल के साथ) ....
Function SUELDOBASICO(Columna As Integer) As Double
On Error GoTo ErrorCheck
Dim CellRef As Range
Dim LookupRef As Range
Set CellRef = Cells(Application.Caller.Range("A1").Row, 3)
Set LookupRef = Application.Caller.Worksheet.Parent.Sheets("Escalas Salariales").Range("A3:DJ23")
SUELDOBASICO = Application.VLookup(CellRef, LookupRef, Columna, False)
Exit Function
ErrorCheck:
Stop
Resume
End Function
(यह भी ध्यान दें कि मैंने बदल दिया Application.WorksheetFunction.VLookup
सेवा मेरे Application.VLookup
- की ओर देखें यह लिंक एक स्पष्टीकरण के लिए)
एक बार जब आप इसे समझ लेंगे, तो मैं फ़ंक्शन से त्रुटि कोड को हटा दूंगा क्योंकि यह "उत्पादन कोड के लिए एक अच्छा विचार नहीं है - बस डिबगिंग के लिए।
उम्मीद है कि आप जो जवाब ढूंढ रहे हैं उसे दे सकते हैं।
उम्मीद है की वो मदद करदे....
अद्यतन # 2:
इस बात को ध्यान में रखते हुए कि शीट की प्रतिलिपि बनाने से यह त्रुटि हो रही है, यहां यह जांचने के लिए एक परीक्षण है कि प्रक्रिया ठीक हो गई है या नहीं:
Function SUELDOBASICO(Columna As Integer) As Double
On Error GoTo ErrorCheck
Dim NumTimesErrored As Integer
Dim StartTime As Double
Dim WaitSeconds As Integer
NumTimesErrored = 0
Dim CellRef As Range
Dim LookupRef As Range
Set CellRef = Cells(Application.Caller.Range("A1").Row, 3)
Set LookupRef = Application.Caller.Worksheet.Parent.Sheets("Escalas Salariales").Range("A3:DJ23")
SUELDOBASICO = Application.VLookup(CellRef, LookupRef, Columna, False)
Exit Function
ErrorCheck:
" This will make it tries this "hack" up to 3 times:
If NumTimesErrored < 3 Then
StartTime = Now
WaitSeconds = 1 " Wait one second
Loop While Now - TimeStart < TimeSerial(0, 0, WaitSeconds)
DoEvents " Allows all the other processes to complete
Loop
" Increment the number of times you"ve tried this:
NumTimesErrored = NumTimesErrored + 1
" Go back to the calculation step that errored
Resume
End If
Stop
Resume
End Function
जवाब के लिए 0 № 2
कॉलर और माता-पिता का उपयोग करने की आवश्यकता नहीं है।
Function SUELDOBASICO(Cell as Range, LookupRange as range, Columna As Integer) As Double
" When you call the function :
" set Cell to be the cell in column C in the same row
" Set LookupRange to Sheets("Escalas Salariales").Range("$A$3:$DJ$23")
SUELDOBASICO = Application.WorksheetFunction.VLookup(Cell, LookupRange, Columna, False)
End Function
एक सेल में सूत्र का उदाहरण ...
= SUELDOBASICO (सी 10, "एस्कलास सालारियल"! $ ए $ 3: $ डीजे $ 23)